/**
 * Created by DevilsEyes on 2016/3/21.
 */
define(['template','jquery'], function (template) {
    var $root = $('#dialog');

    var temp = {
        tips: template.compile('<div class="dialog-tips"><span>{{msg}}</span></div>')
    };

    var symbol = {};

    var dialog = {
        tips: function (msg, time) {
            if (symbol.tips) {
                $('.dialog-tips').remove()
            }
            if (!time || time < 300)time = 3000;
            symbol.tips = true;
            $root.find('#dialogTips').html(temp.tips({msg: msg}));
            var dialog = {
                $: $('.dialog-tips'),
                w: null,
                h: null
            };
            dialog.w = dialog.$.width();
            dialog.h = dialog.$.height();
            dialog.$.css({
                width: 0,
                top: db.h / 2,
                left: db.w / 2,
                height: dialog.h
            });
            ex.async(function () {
                dialog.$.css({
                    width: dialog.w,
                    top: (db.h - dialog.h) / 2,
                    left: (db.w - dialog.w) / 2
                });
            });
            ex.async(function () {
                dialog.$.find('span').css({opacity: 1});
            }, 200);

            setTimeout(function () {
                dialog.$.css({
                    opacity: 0
                });
                ex.async(function () {
                    dialog.$.remove();
                    symbol.tips = false;
                }, 300);
            }, time)

        }
    };

    return dialog;
});